package com.ruoyi.storetype.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storetype.domain.SysStoreType;
import com.ruoyi.storetype.service.ISysStoreTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店类别Controller
 * 
 * @author lb
 * @date 2022-06-07
 */
@RestController
@RequestMapping("/storetype/type")
public class SysStoreTypeController extends BaseController
{
    @Autowired
    private ISysStoreTypeService sysStoreTypeService;

    /**
     * 查询门店类别列表
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStoreType sysStoreType)
    {
        startPage();
        List<SysStoreType> list = sysStoreTypeService.selectSysStoreTypeList(sysStoreType);
        return getDataTable(list);
    }

    /**
     * 导出门店类别列表
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:export')")
    @Log(title = "门店类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStoreType sysStoreType)
    {
        List<SysStoreType> list = sysStoreTypeService.selectSysStoreTypeList(sysStoreType);
        ExcelUtil<SysStoreType> util = new ExcelUtil<SysStoreType>(SysStoreType.class);
        util.exportExcel(response, list, "门店类别数据");
    }

    /**
     * 获取门店类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:query')")
    @GetMapping(value = "/{storeTypeId}")
    public AjaxResult getInfo(@PathVariable("storeTypeId") Long storeTypeId)
    {
        return AjaxResult.success(sysStoreTypeService.selectSysStoreTypeByStoreTypeId(storeTypeId));
    }

    /**
     * 新增门店类别
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:add')")
    @Log(title = "门店类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStoreType sysStoreType)
    {
        return toAjax(sysStoreTypeService.insertSysStoreType(sysStoreType));
    }

    /**
     * 修改门店类别
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:edit')")
    @Log(title = "门店类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStoreType sysStoreType)
    {
        return toAjax(sysStoreTypeService.updateSysStoreType(sysStoreType));
    }

    /**
     * 删除门店类别
     */
    @PreAuthorize("@ss.hasPermi('storetype:type:remove')")
    @Log(title = "门店类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeTypeIds}")
    public AjaxResult remove(@PathVariable Long[] storeTypeIds)
    {
        return toAjax(sysStoreTypeService.deleteSysStoreTypeByStoreTypeIds(storeTypeIds));
    }
}
